/*
 * DetailMessage.java
 *
 * Created on 31 Maret 2008, 13:29
 */
package usu.perpustakaan.buku.widget.operator;

import java.sql.Connection;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import usu.perpustakaan.buku.data.template.Message;
import usu.perpustakaan.buku.data.template.Operator;
import usu.perpustakaan.buku.sql.BookLibrarySQL;
import usu.perpustakaan.buku.widget.template.PanelBlackGreen;
import usu.widget.ButtonGlass;
import usu.widget.util.WidgetUtilities;

/**
 *
 * @author  usu
 */
public class DetailMessage extends PanelBlackGreen {

    private static final long serialVersionUID = -1;
    private Connection connection;

    /** Creates new form BeanForm */
    public DetailMessage() {
        initComponents();
    }

    public ButtonGlass getButtonClose() {
        return buttonClose;
    }

    /**
     * 
     * @param message
     */
    public void setMessage(Message message) {
        textFrom.setText(message.getOperatorFrom());
        textTitle.setText(message.getTitle());
        textMessage.setText(message.getMessage());
        textMessage.append("\n\nDikirim : " + message.getTime().toString());
    }

    /**
     * 
     * @param c
     */
    public void setConnection(Connection c) {
        connection = c;
    }

    /**
     * 
     * @param id
     * @throws java.sql.SQLException
     */
    public void showDetail(String id) throws SQLException {
        Operator op = BookLibrarySQL.getOperator(connection, id);
        if (op == null) {
            WidgetUtilities.showErrorMessage(this, "Operator tak ditemukan, kemungkinan admin telah menghapusnya");
            return;
        }
        textIdOperator.setText(op.getId());
        textalamatoperator.setText(op.getAddress());
        textkontakoperator.setText(op.getContact());
        textnamaOperator.setText(op.getName());
        texttanggallahiroperator.setText(op.getBorn().toString());
        JOptionPane.showMessageDialog(this, PanelDetail, "Detail Operator", JOptionPane.PLAIN_MESSAGE, null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        usu.perpustakaan.buku.widget.template.ViewPortGlass viewPortGlass1 = new usu.perpustakaan.buku.widget.template.ViewPortGlass();
        textMessage = new javax.swing.JTextArea();
        PanelDetail = new javax.swing.JPanel();
        javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel7 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel8 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel9 = new javax.swing.JLabel();
        javax.swing.JScrollPane jScrollPane2 = new javax.swing.JScrollPane();
        textalamatoperator = new javax.swing.JTextArea();
        textIdOperator = new javax.swing.JTextField();
        textnamaOperator = new javax.swing.JTextField();
        texttanggallahiroperator = new javax.swing.JTextField();
        textkontakoperator = new javax.swing.JTextField();
        javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel4 = new javax.swing.JLabel();
        textFrom = new usu.perpustakaan.buku.widget.template.TextBoxGlass();
        textTitle = new usu.perpustakaan.buku.widget.template.TextBoxGlass();
        buttonDetail = new usu.widget.ButtonGlass();
        javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
        buttonClose = new usu.widget.ButtonGlass();

        viewPortGlass1.setView(textMessage);

        textMessage.setColumns(20);
        textMessage.setEditable(false);
        textMessage.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        textMessage.setForeground(new java.awt.Color(255, 255, 255));
        textMessage.setLineWrap(true);
        textMessage.setRows(5);
        textMessage.setWrapStyleWord(true);
        textMessage.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
        textMessage.setFocusAccelerator('I');
        textMessage.setOpaque(false);

        jLabel5.setText("Id");

        jLabel6.setText("Nama");

        jLabel7.setText("Tanggal Lahir");

        jLabel8.setText("Kontak");

        jLabel9.setText("Alamat");

        textalamatoperator.setColumns(20);
        textalamatoperator.setEditable(false);
        textalamatoperator.setFont(new java.awt.Font("Tahoma", 0, 11));
        textalamatoperator.setRows(5);
        jScrollPane2.setViewportView(textalamatoperator);

        textIdOperator.setEditable(false);

        textnamaOperator.setEditable(false);

        texttanggallahiroperator.setEditable(false);

        textkontakoperator.setEditable(false);

        javax.swing.GroupLayout PanelDetailLayout = new javax.swing.GroupLayout(PanelDetail);
        PanelDetail.setLayout(PanelDetailLayout);
        PanelDetailLayout.setHorizontalGroup(
            PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelDetailLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(PanelDetailLayout.createSequentialGroup()
                        .addGroup(PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textnamaOperator, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
                            .addComponent(textIdOperator, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
                            .addComponent(texttanggallahiroperator, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
                            .addComponent(textkontakoperator, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))))
                .addContainerGap())
        );
        PanelDetailLayout.setVerticalGroup(
            PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelDetailLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(textIdOperator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(textnamaOperator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(texttanggallahiroperator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(textkontakoperator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                .addContainerGap())
        );

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Detail Pesan");

        jLabel2.setDisplayedMnemonic('D');
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Dari");

        jLabel3.setDisplayedMnemonic('J');
        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Judul Pesan");

        jLabel4.setDisplayedMnemonic('I');
        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Isi Pesan");

        textFrom.setEditable(false);
        textFrom.setForeground(new java.awt.Color(255, 255, 255));
        textFrom.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textFrom.setFocusAccelerator('D');

        textTitle.setEditable(false);
        textTitle.setForeground(new java.awt.Color(255, 255, 255));
        textTitle.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textTitle.setFocusAccelerator('J');

        buttonDetail.setMnemonic('E');
        buttonDetail.setText("Detail");
        buttonDetail.setRoundRect(true);
        buttonDetail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonDetailActionPerformed(evt);
            }
        });

        jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jScrollPane1.setOpaque(false);
        jScrollPane1.setViewport(viewPortGlass1);

        buttonClose.setMnemonic('T');
        buttonClose.setText("Tutup");
        buttonClose.setRoundRect(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(textFrom, javax.swing.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(buttonDetail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(textTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)))
                    .addComponent(buttonClose, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(buttonDetail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(textTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonClose, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void buttonDetailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDetailActionPerformed
    try {
        showDetail(textFrom.getText());//GEN-LAST:event_buttonDetailActionPerformed
        } catch (SQLException ex) {
            WidgetUtilities.showErrorMessage(this, ex.getMessage());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JPanel PanelDetail;
    usu.widget.ButtonGlass buttonClose;
    usu.widget.ButtonGlass buttonDetail;
    usu.perpustakaan.buku.widget.template.TextBoxGlass textFrom;
    javax.swing.JTextField textIdOperator;
    javax.swing.JTextArea textMessage;
    usu.perpustakaan.buku.widget.template.TextBoxGlass textTitle;
    javax.swing.JTextArea textalamatoperator;
    javax.swing.JTextField textkontakoperator;
    javax.swing.JTextField textnamaOperator;
    javax.swing.JTextField texttanggallahiroperator;
    // End of variables declaration//GEN-END:variables
}
